﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="config" xmlns="urn:startuptaskrunner/2010/12" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:startuptaskrunner/2010/12" elementFormDefault="qualified">
  <xs:element name ="Config" type="ConfigType"/>
  <xs:complexType name ="ConfigType">
    <xs:sequence>
      <xs:element name="BlobStorage" type="BlobStorageType" nillable="false" minOccurs="1" maxOccurs="1"/>
      <xs:element name="Tasks" type="TasksCollectionType" minOccurs="1" maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name ="BlobStorageType">
    <xs:annotation>
      <xs:documentation>Defines the Azure Storage account and default container</xs:documentation>
    </xs:annotation>
    <xs:attribute name="defaultContainer" type="xs:string" use="required" />
    <xs:attribute name="name" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation>Name of the Azure Storage account</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="key" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation>Primary key of the Azure Storage account</xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name ="TasksCollectionType">
    <xs:annotation>
      <xs:documentation>Collection of tasks to execute at startup of the role instance</xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="Task" type="TaskType" minOccurs="1" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name ="TaskType">
    <xs:sequence minOccurs="1" maxOccurs="unbounded">
      <xs:choice>
        <xs:element name="Copy" type="CopyType" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element name="Run" type="RunType" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element name="InstallCertificate" type="InstallCertificateType" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element name="UnZip" type="UnZipType" minOccurs="0" maxOccurs="unbounded"/>
      </xs:choice>
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
  </xs:complexType>

  <xs:complexType name ="CopyType">
    <xs:annotation>
      <xs:documentation>Task: copy a resource from blob storage to the local drive</xs:documentation>
    </xs:annotation>
    <xs:complexContent>
      <xs:extension base="ActionType">
        <xs:attribute name="containerName" type="xs:string">
          <xs:annotation>
            <xs:documentation>Name of the container that holds the resource</xs:documentation>
          </xs:annotation>
        </xs:attribute>
        <xs:attribute name="sourceFile" type="xs:string">
          <xs:annotation>
            <xs:documentation>Name of the resource to be copied</xs:documentation>
          </xs:annotation>
        </xs:attribute>
        <xs:attribute name="destinationLocation" type="xs:string" />
        <xs:attribute name="overwrite" type="xs:boolean" default="true" />
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name ="UnZipType">
    <xs:annotation>
      <xs:documentation>Task: unzip an archive from blob storage to the local drive</xs:documentation>
    </xs:annotation>
    <xs:complexContent>
      <xs:extension base="ActionType">
        <xs:attribute name="containerName" type="xs:string">
          <xs:annotation>
            <xs:documentation>Name of the container that holds the archives. When only the containerName is specified, all archives in the container will be unzipped in the specified destination.</xs:documentation>
          </xs:annotation>
        </xs:attribute>
        <xs:attribute name="archiveName" type="xs:string">
          <xs:annotation>
            <xs:documentation>Name of the archive to be unzipped. When the archiveName is left blank, all archives in the specified container will be unzipped.</xs:documentation>
          </xs:annotation>
        </xs:attribute>
        <xs:attribute name="destinationLocation" type="xs:string" />
        <xs:attribute name="overwrite" type="xs:boolean" default="true" />
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name ="RunType">
    <xs:annotation>
      <xs:documentation>Task: runs a command</xs:documentation>
    </xs:annotation>
    <xs:complexContent>
      <xs:extension base="ActionType">
        <xs:attribute name="commandFile" type="xs:string" use="required" />
        <xs:attribute name="commandArguments" type="xs:string" use="optional"/>
        <xs:attribute name="timeout" type="xs:int" use="optional" />
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name ="InstallCertificateType">
    <xs:annotation>
      <xs:documentation>Task: installs a certificate (*.cer file, pfx files can be uploaded using the portal)</xs:documentation>
    </xs:annotation>
    <xs:complexContent>
      <xs:extension base="ActionType">
        <xs:attribute name="certificateFile" type="xs:string" use="required" />
        <xs:attribute name="certificateStoreName" type="xs:string" use="required"/>
        <xs:attribute name="certificateStoreLocation" type="CertificateStoreLocation" use="optional" />
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:simpleType name ="CertificateStoreLocation">
    <xs:annotation>
      <xs:documentation>Specifies the StoreLocation: CurrentUser or LocalMachine</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:enumeration value="CurrentUser"/>
      <xs:enumeration value="LocalMachine"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name ="ActionType">
  </xs:complexType>
</xs:schema>